package com.github.appintro;

import com.github.appintro.component.ArrowView;
import com.github.appintro.component.DoneView;
import com.github.appintro.component.SkipView;
import com.github.appintro.utile.ResUtil;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Image;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

public abstract class AppIntro2 extends AppIntroBase {
    private DependentLayout backgroundFrame;
    private Component bottomBar;
    private Image skipImageButton;
    protected int backgroundResource;

    public void setLayoutId() {
        layoutId = ResourceTable.Layout_appintro_intro_layout2;
    }

    public int getBackgroundResource() {
        return backgroundResource;
    }

    public void setBackgroundResource(int backgroundResource) {
        this.backgroundResource = backgroundResource;
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setShape(backgroundResource);
        backgroundFrame.setBackground(shapeElement);
    }

    @Override
    public void onStart(Intent savedInstanceState) {
        super.onStart(savedInstanceState);
        backgroundFrame = (DependentLayout) findComponentById(ResourceTable.Id_background);
        bottomBar = findComponentById(ResourceTable.Id_bottom);
        skipImageButton = (Image) findComponentById(ResourceTable.Id_skip);
    }

    /**
     * Override viewpager bar color
     *
     * @param rgbRes your color resource
     */
    public void setBarColor(int rgbRes) {
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setShape(rgbRes);
        bottomBar.setBackground(shapeElement);
    }

    /**
     * Override next button arrow color
     *
     * @param rgbRes your color resource
     */
    public void setNextArrowColor(int rgbRes) {
        ArrowView nextButton = (ArrowView) findComponentById(ResourceTable.Id_next);
        nextButton.setColor(new Color(ResUtil.getColor(getContext(), rgbRes)));
    }

    /**
     * Override skip button color
     *
     * @param rgbRes your color resource
     */
    public void setSkipArrowColor(int rgbRes) {
        SkipView skip = (SkipView) findComponentById(ResourceTable.Id_skip);
        skip.setColor(new Color(ResUtil.getColor(getContext(), rgbRes)));
    }

    public void setDoneColor(int rgbRes) {
        DoneView done = (DoneView) findComponentById(ResourceTable.Id_done);
        done.setColor(new Color(ResUtil.getColor(getContext(), rgbRes)));
    }
}
